import React, { Component } from 'react';
import {connect} from "react-redux";
import View from './pages/view';
import Add from './pages/add';
import {INIT_ITEMS} from "./actions";
import get from "./data";
//引入路由
import {BrowserRouter as Router, Route, Link} from 'react-router-dom';



class App extends Component {
  constructor(...args){
    super(...args);

    this.state={
      panelShow: false
    };
  } 
  async componentDidMount(){
    let {data}=await get("list");
    this.props.initItems(data);
  }
  render() {
    return (
      <Router>
        <div>
          <Link className="btn btn-default glyphicon glyphicon-plus" to="/add">添加商品</Link>
          <Route path="/" exact component={View} />
          <Route path="/add" component={Add} />
        </div>
      </Router>
    );
  }
}

export default connect(function(state,props){
  return state
},{
  initItems(items){
    return {
      type:"INIT_ITEMS",
      items
    }
  }
})(App);
